/**
 * title: 登录
 */
import React from 'react';
import LoginForm from './components/LoginForm';
import Link from 'umi/link';
import LoginWrapper from '@/components/LoginWrapper';
import qs from 'qs';
const { Welcome } = LoginWrapper;
const users = ['user', 'admin'];
const loginTypes = ['msg', 'pwd'];
const getPartRightComponent = (userType, loginType) => {
  if (users.includes(userType) && loginTypes.includes(loginType)) {
    return props => <LoginForm {...props} userType={userType} loginType={loginType} />;
  }
  return props => <LoginForm {...props} userType="user" loginType="pwd" />;
};
const Login = ({ location: { search }, history }) => {
  const params = qs.parse(search, { ignoreQueryPrefix: true });
  const { userType = 'user', loginType = 'pwd' } = params;
  const FormComponent = getPartRightComponent(userType, loginType);
  return (
    <div style={{ height: '100%', width: '100%', background: '#f9f9f9' }}>
      <div className="toggle-page-actions-wrapper">
        <span>登录</span>
        <Link to="/register">注册</Link>
      </div>
      <LoginWrapper
        partLeft={<Welcome showLinks={userType === 'user'} />}
        partRight={<FormComponent history={history} />}
      />
    </div>
  );
};
export default Login;
